//
//  HACNodesComponent.h
//  HStockCharts
//
//  Created by Hotacool on 2018/9/21.
//

#import <UIKit/UIKit.h>
#import "HACFocusProvider.h"
#import "HACBasicComponents.h"
#import "HACChartNode.h"
extern CGFloat refreshOffsetX;
@class HACNodesComponent;
@protocol HACNodesComponentDelegate <NSObject>
@optional
- (void)nodeComponentNeedRefresh:(HACNodesComponent*)component ;

- (void)tapednodeComponent:(HACNodesComponent*)component gesture:(UIGestureRecognizer*)gesture ;

- (void)dragnodeComponent:(HACNodesComponent*)component gesture:(UIGestureRecognizer*)gesture ;

/// 长按显示X轴坐标值
/// @param component chart组件
/// @param index focus坐标索引
/// @param xAxisStr x轴上
/// @param extStr x轴下
- (void)nodeComponent:(HACNodesComponent*)component focusAtIndex:(NSInteger)index xAxisString:(NSString**)xAxisStr extString:(NSString**)extStr;

/// 长按显示Y轴坐标值
/// @param component chart组件
/// @param index focus坐标索引
/// @param yAxisStr y轴左
/// @param extStr y轴右
- (void)nodeComponent:(HACNodesComponent*)component focusAtIndex:(NSInteger)index yAxisString:(NSString**)yAxisStr extString:(NSString**)extStr;

@end

@interface HACNodesComponent : UIView <HACFocusProvider>
@property (nonatomic, strong) HACChartData *data;
@property (nonatomic, weak) id<HACNodesComponentDelegate> delegate;

@property (nonatomic, strong, readonly) UIScrollView *contentScroll;
@property (nonatomic, strong) UIView *marketTimeBar;
@property (nonatomic, assign) BOOL isRefresh; //刷新，load more
@property (nonatomic, strong) UIActivityIndicatorView *refreshIndicator;
/** 当前焦点所在index */
@property (nonatomic, assign) NSInteger focusIndex;
@property (nonatomic, assign) NSInteger focusItemsCount; /** 默认1，只绘制竖线，需要绘制横线指示设置成2 */
@property (nonatomic, strong, readonly) UILabel *xCursorLabelUp; // y轴的文字提示
@property (nonatomic, strong, readonly) UILabel *xCursorLabelDown; // y轴的文字提示
@property (nonatomic, strong, readonly) UILabel *yCursorLabelLeft; // x轴的文字提示
@property (nonatomic, strong, readonly) UILabel *yCursorLabelRight; // x轴的文字提示
@property (nonatomic, strong, readonly) CAShapeLayer *focusLayer;

@property (nonatomic, strong, readonly) HACFocusComponents *focusComponent;
@property (nonatomic, assign) CGPoint focusPoint;
@property (nonatomic, assign) BOOL focusEnable; //是否焦点
@property (nonatomic, assign) BOOL isFocusing; //是否正在聚焦
//倒序index，K线图默认显示最新时间段K线
@property (nonatomic, assign) NSInteger indexFromEnd;
// 处理缩放
@property (nonatomic) CGFloat lastScale;    /** 上一次缩放比例 */
@property (nonatomic) CGFloat lastEndScale; /** 上次结束最后缩放值，也是当次初始值，用于指示当前相对默认的比例 */

@property (nonatomic, strong) NSMutableDictionary<NSString* ,HACChartNode*> *nodeDic;
@property (nonatomic, assign) NSInteger visualCount;

- (void)refreshUI ;
//尽量保持offset，右方新增数据；不同于setdatah会重置offset
- (void)refreshUIWithData:(HACChartData*)data ;
- (void)endRefreshWithData:(HACChartData *)data ;
- (void)clearContents;
- (void)hiddenFocusLayer;
#pragma mark -- protect method
- (void)updateContentScrollSize ;
- (NSArray<NSString*>*)stringForFocusItem:(HACFocusComponents *)focusItem focusIndex:(NSInteger)focusIndex ;
- (void)setUpMarketTimeBarWithTimeArray:(NSArray*)timesArray ;
#pragma mark -- gestures
- (void)reactForTapGesture:(UITapGestureRecognizer *)gesture ;
- (void)reactForLongPressGesture:(UILongPressGestureRecognizer*)gesture ;
- (void)reactForPinchGesture:(UIPinchGestureRecognizer *)gesture ;
- (void)reactForContentViewDidScroll:(UIScrollView *)scrollView ;
@end
